import request from "../utils/request";

interface ResponseType<T> {
  code: number;
  success: boolean;
  message: string;
  data: T;
}

interface ArticleDetail {
  id: string;
  author: string;
  title: string;
  avatar: string;
  content: string;
}

interface ArticleItem {
  id: string;
  author: string;
  createTime: string;
  categoryList: string[];
  title: string;
  content: string;
  viewNum: string;
  loveNum: string;
  commentNum: string;
}

export type Articles = ArticleItem[];

export const reqGetArticles = () => {
  /*
    实际响应数据类型：
      AxiosResponse<ResponseType<Articles>>
      { // 整体AxiosResponse
        headers: xxx,
        status: xxx,
        data: { // data就是ResponseType类型
          code: 200,
          message: '',
          success: true,
          data: Articles
        }
      }
  */
  return request.get<ResponseType<Articles>>("/articles");
};

export const reqGetArticleDetail = (id: string) => {
  return request.get<ResponseType<ArticleDetail>>(`/article/${id}`);
};
